﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class appleader_projects_start : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void start(object sender, EventArgs e)
    {
        if (Request["projectid"] != null)
        {
            int projectid = int.Parse(Request["projectid"].ToString());
            if (MasApp.BLL.Update.StartProject(projectid))
            {
                if (MasApp.BLL.Search.SearchProjectWeightType(projectid) == "直接赋权")
                {
                    MasApp.Model.weightmission wm = new MasApp.Model.weightmission();
                    wm.Actor = Session["username"].ToString();
                    wm.Projectid = projectid;
                    wm.Weightmissiontype = "直接赋权";
                    //直接赋权则状态为“有效的”
                    wm.State = "有效的";
                    wm.Weightmissionid = MasApp.BLL.reg.RegWeightMission(wm);

                    //初始化准则权值为0
                    DataTable dt = MasApp.BLL.Search.SearchRuleIDandName(projectid);
                    MasApp.Model.weight we = new MasApp.Model.weight();
                    we.Weightvalue = 0;
                    we.Weightmissionid = wm.Weightmissionid;

                    int rulenum = dt.Rows.Count;
                    for (int k = 0; k < rulenum; k++)
                    {
                        we.Elementtype = "准则";
                        we.Elementid = Convert.ToInt32(dt.Rows[k][0].ToString());
                        we.Weightid = MasApp.BLL.reg.RegWeight(we);
                        //初始化指标权值
                        DataTable dt_indi = MasApp.BLL.Search.SearchIndicatorIDsandNames(we.Elementid);
                        int indinum = dt_indi.Rows.Count;
                        for (int kk = 0; kk < indinum; kk++)
                        {
                            we.Elementtype = "指标";
                            we.Elementid = Convert.ToInt32(dt_indi.Rows[kk][0].ToString());
                            we.Weightid = MasApp.BLL.reg.RegWeight(we);
                        }
                    }

                    MasApp.BLL.ResponseHelper.alert("成功，现在去添加专家", "addmission.aspx?projectid="+projectid);
                }
                else
                {
                    MasApp.BLL.ResponseHelper.alert("成功，现在去添加专家", "addmission.aspx?projectid=" + projectid);
                }
            }
            else
            {

                MasApp.BLL.ResponseHelper.alert("失败", "startlist.aspx");
            }
        }
        else
        {

            MasApp.BLL.ResponseHelper.alert("非法", "startlist.aspx");
        }
    }
}
